home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / bin / zcmp < prev    next >
Text File  |  1995-07-17  |  2KB  |  70 lines

  1. #!/bin/sh
  2. # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
  3.  
  4. # Zcmp and zdiff are used to invoke the cmp or the  diff  pro-
  5. # gram  on compressed files.  All options specified are passed
  6. # directly to cmp or diff.  If only 1 file is specified,  then
  7. # the  files  compared  are file1 and an uncompressed file1.gz.
  8. # If two files are specified, then they are  uncompressed  (if
  9. # necessary) and fed to cmp or diff.  The exit status from cmp
  10. # or diff is preserved.
  11.  
  12. PATH="/usr/skunk/bin:$PATH"; export PATH
  13. prog=`echo $0 | sed 's|.*/||'`
  14. case "$prog" in
  15.   *cmp) comp=${CMP-cmp}   ;;
  16.   *)    comp=${DIFF-diff} ;;
  17. esac
  18.  
  19. OPTIONS=
  20. FILES=
  21. for ARG
  22. do
  23.     case "$ARG" in
  24.     -*)    OPTIONS="$OPTIONS $ARG";;
  25.      *)    if test -f "$ARG"; then
  26.             FILES="$FILES $ARG"
  27.         else
  28.             echo "${prog}: $ARG not found or not a regular file"
  29.         exit 1
  30.         fi ;;
  31.     esac
  32. done
  33. if test -z "$FILES"; then
  34.     echo "Usage: $prog [${comp}_options] file [file]"
  35.     exit 1
  36. fi
  37. set $FILES
  38. if test $# -eq 1; then
  39.     FILE=`echo "$1" | sed 's/[-.][zZtga]*$//'`
  40.     gzip -cd "$1" | $comp $OPTIONS - "$FILE"
  41.     STAT="$?"
  42.  
  43. elif test $# -eq 2; then
  44.     case "$1" in
  45.         *[-.]gz* | *[-.][zZ] | *.t[ga]z)
  46.                 case "$2" in
  47.             *[-.]gz* | *[-.][zZ] | *.t[ga]z)
  48.             F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'`
  49.                         gzip -cdfq "$2" > /tmp/"$F".$$
  50.                         gzip -cdfq "$1" | $comp $OPTIONS - /tmp/"$F".$$
  51.                         STAT="$?"
  52.             /bin/rm -f /tmp/"$F".$$;;
  53.  
  54.                 *)      gzip -cdfq "$1" | $comp $OPTIONS - "$2"
  55.                         STAT="$?";;
  56.                 esac;;
  57.         *)      case "$2" in
  58.             *[-.]gz* | *[-.][zZ] | *.t[ga]z)
  59.                         gzip -cdfq "$2" | $comp $OPTIONS "$1" -
  60.                         STAT="$?";;
  61.                 *)      $comp $OPTIONS "$1" "$2"
  62.                         STAT="$?";;
  63.                 esac;;
  64.     esac
  65.         exit "$STAT"
  66. else
  67.     echo "Usage: $prog [${comp}_options] file [file]"
  68.     exit 1
  69. fi
  70.